package test;

import java.util.Set;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.exceptions.JedisConnectionException;

/**   
 * Redis操作接口
 *
 * @author 林计钦
 * @version 1.0 2013-6-14 上午08:54:14   
 */
public class MyJedisPool {
    private static JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost");
    
    public static void main(String [] args) {
    	Jedis jedis = pool.getResource();
    	try {
    	  /// ... do stuff here ... for example
    	  jedis.set("foo", "bar");
    	  String foobar = jedis.get("foo");
    	  jedis.zadd("sose", 0, "car"); jedis.zadd("sose", 0, "bike"); 
    	  Set<String> sose = jedis.zrange("sose", 0, -1);
    	} catch (JedisConnectionException e) {
    	    // returnBrokenResource when the state of the object is unrecoverable
    	    if (null != jedis) {
    	        pool.returnBrokenResource(jedis);
    	        jedis = null;
    	    }
    	} finally {
    	  /// ... it's important to return the Jedis instance to the pool once you've finished using it
    	  if (null != jedis)
    	    pool.returnResource(jedis);
    	}
    	/// ... when closing your application:
    	pool.destroy();
    }
   
    
    
   
}